package com.neuedu.live;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.ObjectInputStream;
import java.net.Socket;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

public class Student {

	public static void main(String[] args) throws Exception {
		
		JFrame jFrame = new JFrame("Living");
		int width = 800;
		int height = 600;
		
		jFrame.setSize(width, height);
		jFrame.setLocationRelativeTo(null);
		jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
		DrawCanvas canvas = new DrawCanvas(image, width, height);
		Graphics g = image.getGraphics();
		
		jFrame.add(canvas);
		jFrame.setVisible(true);
		
		
		
		Socket socket = new Socket("localhost", 10001);
		ObjectInputStream in = new ObjectInputStream(socket.getInputStream());

		try {
			while(true) {
				ImageIcon icon = (ImageIcon) in.readObject();
				g.drawImage(icon.getImage(), 0, 0,width,height,canvas);
				canvas.repaint();
			}
		}catch (Exception e) {
			e.printStackTrace();
		}finally {
			in.close();
			socket.close();
		}
	}

}
